package com.zhangsr.zus.remoting.api.exchange.support.header;

import com.zhangsr.zus.common.URL;
import com.zhangsr.zus.remoting.api.Transporters;
import com.zhangsr.zus.remoting.api.exception.RemotingException;
import com.zhangsr.zus.remoting.api.exchange.ExchangeClient;
import com.zhangsr.zus.remoting.api.exchange.ExchangeHandler;
import com.zhangsr.zus.remoting.api.exchange.ExchangeServer;
import com.zhangsr.zus.remoting.api.exchange.Exchanger;
import com.zhangsr.zus.remoting.api.transport.DecodeHandler;

/**
 * @Author: zhangsr
 */
public class HeaderExchanger implements Exchanger {


    public ExchangeClient connect(URL url, ExchangeHandler handler) throws RemotingException {
        return new HeaderExchangeClient(Transporters.connect(url, new DecodeHandler(new HeaderExchangeHandler(handler))));
    }

    public ExchangeServer bind(URL url, ExchangeHandler handler) throws RemotingException {
        return new HeaderExchangeServer(Transporters.bind(url, new DecodeHandler(new HeaderExchangeHandler(handler))));
    }

}
